import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Solution843 {

    static class Master {

        String target;
        int time=0;

        public Master(String t){
            target=t;
        }

        public int guess(String word) {
            time++;
            if (time>10){
                System.out.println("Fail!");
            }
            int ans=0;
            for (int i=0;i<6;i++){
                if (target.charAt(i)==word.charAt(i)){
                    ans++;
                }
            }
            return ans;
        }
    }

    public void findSecretWord(String[] wordlist, Master master) {
        if (wordlist.length<10){
            for (String s : wordlist) {
                master.guess(s);
            }
        }else{
            Set<String> strings=new HashSet<>(Arrays.asList(wordlist));
            while (strings.size()>0){
                String s= (String) strings.toArray()[(int)(Math.random()*strings.size())];
                int a=master.guess(s);
                if (a==6){
                    return;
                }
                Set<String> newStrings=new HashSet<>();
                for (String string : strings) {
                    if (compare(string,s)==a){
                        newStrings.add(string);
                    }
                }
                strings=newStrings;
            }
        }
    }

    public int compare(String a,String b) {
        int ans=0;
        for (int i=0;i<6;i++){
            if (a.charAt(i)==b.charAt(i)){
                ans++;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        new Solution843().findSecretWord(new String[]{"gaxckt","trlccr","jxwhkz","ycbfps","peayuf","yiejjw","ldzccp","nqsjoa","qrjasy","pcldos","acrtag","buyeia","ubmtpj","drtclz","zqderp","snywek","caoztp","ibpghw","evtkhl","bhpfla","ymqhxk","qkvipb","tvmued","rvbass","axeasm","qolsjg","roswcb","vdjgxx","bugbyv","zipjpc","tamszl","osdifo","dvxlxm","iwmyfb","wmnwhe","hslnop","nkrfwn","puvgve","rqsqpq","jwoswl","tittgf","evqsqe","aishiv","pmwovj","sorbte","hbaczn","coifed","hrctvp","vkytbw","dizcxz","arabol","uywurk","ppywdo","resfls","tmoliy","etriev","oanvlx","wcsnzy","loufkw","onnwcy","novblw","mtxgwe","rgrdbt","ckolob","kxnflb","phonmg","egcdab","cykndr","lkzobv","ifwmwp","jqmbib","mypnvf","lnrgnj","clijwa","kiioqr","syzebr","rqsmhg","sczjmz","hsdjfp","mjcgvm","ajotcx","olgnfv","mjyjxj","wzgbmg","lpcnbj","yjjlwn","blrogv","bdplzs","oxblph","twejel","rupapy","euwrrz","apiqzu","ydcroj","ldvzgq","zailgu","xgqpsr","wxdyho","alrplq","brklfk"},new Master("hbaczn"));
    }
}
